﻿using GLog;
using System;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            ILog log = new ConsoleLog();
            log = new BufferedTextFileLog("Demo.log", log, LogLevel.Error | LogLevel.Warning);

            try
            {
                // Initialize
                log.Initial();

                // Header
                log.LogHeader("Start the Demo.");

                // Message
                log.LogMessage(string.Format("{0}: {1}", DateTime.Now, "Hello. This is a message log."));

                // Warning
                log.LogWarning(string.Format("{0}: {1}", DateTime.Now, "I am going to throw an exception next."));

                // Throw an exception and log an error
                throw new InvalidOperationException("I throw this error to test the error log.");
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message);
                log.LogError(ex.StackTrace);
            }
            finally
            {
                log.WriteLog();
            }

            Console.WriteLine("Press any key to continue . . .");
            Console.ReadKey(true);
        }
    }
}
